package com.youlu.campus.web.complaint;

import com.youlu.campus.web.common.base.RequestContext;
import com.youlu.campus.web.cms.entity.ComplaintInfo;
import com.youlu.campus.web.cms.service.ComplaintInfoService;
import com.youlu.campus.web.cms.vo.ComplaintInfoCreateRequest;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 投诉API
 *
 * @author: zhuhuaiqi
 * @date: 2020/12/7 17:05
 */
@RestController
public class ComplaintController {
    @Autowired
    private ComplaintInfoService complaintInfoService;
    @Value("${campus.defaultTenantId:5fc5e0c6b8016b1f865aa02f}")
    private String defaultTenantId;

    /**
     * 新建投诉API
     * 备注：新建投诉
     * 参数：request - 新建投诉请求类
     * 返回：200-请求成功，返回Boolean类型结果（表示操作是否成功）
     */
    @PostMapping("/mini-app/complaint/create")
    public QResult create(@RequestBody ComplaintInfoCreateRequest request) {
        ComplaintInfo info = new ComplaintInfo();
        BeanUtils.copyProperties(request, info);
        info.setComplaintUserId(RequestContext.getUserId());
        boolean r = complaintInfoService.create(defaultTenantId, info);
        if (r) {
            return QResult.success(r);
        }
        return QResult.fail("创建投诉失败");
    }
}